<?php
namespace Home\Controller;
use Think\Controller;
class CommonController extends Controller {

    public function _initialize()
    {
        

        $paths = MODULE_NAME.'/'.CONTROLLER_NAME.'/'.ACTION_NAME;

        // var_dump(C('AUTH_PATHS'));

        // var_dump($paths);

        if(in_array($paths, C('AUTH_PATHS'))){
            if(!isset($_SESSION['id'])){
                $this->error('请先登录',U('home/login/index'));
            }
        }

    }

    public function autoAdd($table,$filed,$num,$id){

    	$sql = "update ".$table." set " .$filed ."=".$filed.$num ." where id='{$id}'";

    	M()->execute($sql);
    }

    public function getTopView()
    {
    	// M('question')->order("order by view_num desc")->limit(10)->select();
    	// 
    	$sql = "select * from question order by view_num desc limit 10";

    	$hotView = M()->query($sql);

    	$this->assign('hotView',$hotView);
    }

    public function getTopAnswer()
    {
    	$sql = "select * from question order by answer_num desc limit 10";

    	$hotAnsewr = M()->query($sql);



    	$this->assign('hotAnsewr',$hotAnsewr);
    }

    public function getTopUser()
    {
    	$sql = "select * from user order by answer_num desc limit 12";

    	$hotUser = M()->query($sql);

    	$this->assign('hotUser',$hotUser);
    }


}